﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Songhay.Extensions;
using System;
using System.Linq;
using System.Windows.Markup;

namespace Songhay.BiggestBox.Desktop.Modules.SvgFonts.Tests
{
    /// <summary>
    /// Tests for <see cref="PackedXmlViewModel"/>
    /// </summary>
    [TestClass]
    public class PackedXmlViewModelTest
    {
        /// <summary>
        /// Initializes the test.
        /// </summary>
        [TestInitialize]
        public void InitializeTest()
        {
            this.TestContext.RemovePreviousTestResults();
        }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Packed XML view model test: should list packed resources.
        /// </summary>
        [TestMethod]
        public void ShouldListPackedResources()
        {
            var type = typeof(SvgFontsModule);
            var resources = ApplicationUtility.ListPackedResources(type.Assembly);
            Assert.IsTrue(resources.Any(), "The expected resources are not here.");
            resources.ForEachInEnumerable(i => this.TestContext.WriteLine("{0}\nUri: {1}\nDisplay Text: {2}", i, i.ResourceIndicator, i.DisplayText));
        }

        /// <summary>
        /// Packed xml view model test: should load packed resource.
        /// </summary>
        [TestMethod]
        [TestProperty("href", "/Songhay.BiggestBox.Desktop.Modules.SvgFonts;Component/packedxml/fontawesome-webfont.svg")]
        public void ShouldLoadPackedResource()
        {
            var href = this.TestContext.Properties["href"].ToString();
            var uri = new Uri(href, UriKind.Relative);
            var resource = ApplicationUtility.LoadResource(uri);
            Assert.IsNotNull(resource, "The expected Resource is not here.");
            this.TestContext.WriteLine(resource);
        }
    }
}
